<template>
  <el-select v-model="code" :placeholder="placeholder" :multiple="multiple" :clearable="clearable" style="width:100%;" :disabled="disabled">
    <el-option v-for="item in kanaList" :key="item.id" :value="item" :label="changeName(item)"></el-option>
  </el-select>
</template>

<script>
  export default {
    data() {
      return {
        kanaList: [],
        code: this.value
      };
    },
    props: {
      type: {
        type: String,
        default: 'name'
      },
      value: {
        type: [String, Array],
        default: ''
      },
      placeholder: {
        type: String,
        default: ''
      },
      disabled: {
        type: Boolean,
        default: false
      },
      clearable: {
        type: Boolean,
        default: true
      },
      multiple: {
        type: Boolean,
        default: false
      }
    },
    watch: {
      code(val, oldVal) {
        if (val !== oldVal) {
          this.$emit('input', this.code);
          this.$emit('change');
        }
      },
      value(val, oldVal) {
        this.code = val;
      }
    },
    methods: {
      changeName(name){
        let result = name;
        if (name == 'Logicash-A') {
          result = 'Topeso-A'
        };
        if (name == 'Logicash-B') {
          result = 'Topeso-B'
        };
        if (name == 'Logicash-C') {
          result = 'Topeso-C'
        };
        if (name == 'Logicash-D') {
          result = 'Topeso-D'
        };
          return result
        },
      async getKanaProductName() {
          console.warn('dasds')
        const {
          status,
          data,
          error
        } = await this.$api.finance.productSetting.getKanaProductName();
        if ('1' === status && error === '00000000') {
          this.kanaList = data || [];
          this.$emit('giveParentData', data);
        }
      }
    },
    created() {
      this.getKanaProductName();
    }
  };
</script>

<style scoped>
</style>

